package cn.tedu.project.oa.note.service.impl;

import cn.tedu.project.oa.base.response.PageData;
import cn.tedu.project.oa.note.mapper.NoteMapper;
import cn.tedu.project.oa.note.pojo.dto.NoteQuery;
import cn.tedu.project.oa.note.pojo.dto.NoteSaveParam;
import cn.tedu.project.oa.note.pojo.entity.Note;
import cn.tedu.project.oa.note.pojo.vo.NoteVO;
import cn.tedu.project.oa.note.service.NoteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class NoteServiceImpl implements NoteService {

    @Autowired
    NoteMapper noteMapper;

    @Override
    public PageData selectList(NoteQuery noteQuery) {
        log.debug("查询备忘录列表业务:noteQuery={}",noteQuery);

        List<NoteVO> list = noteMapper.selectList(noteQuery);

        PageData pageData = new PageData();
        pageData.setList(list);
        pageData.setTotal(noteMapper.selectCount(noteQuery));

        return pageData;
    }

    @Override
    public NoteVO selectById(Long id) {
        log.debug("显示备忘详情业务：id={}",id);

        NoteVO noteVO = noteMapper.selectById(id);

        return noteVO;
    }

    @Override
    public void saveNote(NoteSaveParam noteSaveParam) {
        log.debug("发布备忘:noteSaveParam={}",noteSaveParam);

        Note note = new Note();
        BeanUtils.copyProperties(noteSaveParam,note);
        note.setCreateTime(new Date());
        note.setStatus(10);
//        note.setUserId(20000l);
//        note.setDepartmentId(100l);

        noteMapper.insert(note);
    }

    @Override
    public void deleteById(Long id) {
        log.debug("删除备忘录:id={}",id);

        noteMapper.deleteById(id);
    }
}
